home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABUFSSpecs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-23  |  6.7 KB  |  244 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was created & modified by George (ty) Tempel in 
  8.     connection with TopSoft, Inc. from Apple DTS source code:
  9.     
  10.         Apple Macintosh Developer Technical Support
  11.     
  12.         A collection of useful high-level File Manager routines.
  13.     
  14.         by Jim Luther, Apple Developer Technical Support
  15.     
  16.         from File:        MoreFilesExtras.c
  17.     
  18.         Copyright © 1992-1994 Apple Computer, Inc.
  19.         All rights reserved.
  20.     
  21.         You may incorporate this sample code into your applications without
  22.         restriction, though the sample code has been provided "AS IS" and the
  23.         responsibility for its operation is 100% yours.  However, what you are
  24.         not permitted to do is to redistribute the source as "DSC Sample Code"
  25.         after having made changes. If you're going to re-distribute the source,
  26.         we require that you make it clear in the source that the code was
  27.         descended from Apple Sample Code, but that you've made changes.
  28.  
  29.     See the Modification History for more details.
  30.  
  31. Product
  32.     About Box
  33.  
  34. FILE
  35.     ABUFSSpecs.c
  36.  
  37. NAME
  38.     ABUFSSpecs.c, part of the ABox project source code,
  39.     responsible for utility handling the AboutBox FSSpecs stuff.
  40.  
  41. DESCRIPTION
  42.     This file contains methods for the ABUFSSpecs class.
  43.     
  44. DEVELOPED BY
  45.     George (ty) Tempel                netromancr@aol.com
  46.     All code in this file, and its associated header file was
  47.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  48.     "FilterTop" application development, except where noted.
  49.  
  50. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  51.      Please consult this person for any changes or suggestions to this file.
  52.  
  53. MODIFICATION HISTORY
  54.  
  55.     dd mmm yy    -    xxx    -    patchxx: description of patch
  56.     15 july 94    -    ty    -    Initial Version Created
  57.     20-july-94    -    ty    -    initial version released
  58.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  59.                             release and the associated Universal Headers from Apple:
  60.                             most methods that returned references now have "Ref" at
  61.                             the end of their methods names to prevent possible collisions
  62.                             with datatypes and classes of the same name (older versions
  63.                             of the compiler didn't have a problem with this).
  64.  
  65. */
  66.  
  67. /*===========================================================================*/
  68.  
  69. /*======= Segmentation directives ========*/
  70. #ifdef USE_MANUAL_SEGMENTATION
  71. #pragma segment ty
  72. #endif
  73.  
  74. /*============ Header files ==============*/
  75.  
  76. #include    "ABUFSSpecs.h"
  77.  
  78.  
  79. /*=============== Globals ================*/
  80.  
  81. /*================ CODE ==================*/
  82.  
  83.  
  84.  
  85. /*========================= ABUFSSpecs::ABUFSSpecs =================================*/
  86. ABUFSSpecs::ABUFSSpecs (void)
  87. {
  88.     //    do nothing!
  89. } // end ABUFSSpecs
  90.  
  91.  
  92.  
  93.  
  94. /*========================= ABUFSSpecs::~ABUFSSpecs =================================*/
  95. ABUFSSpecs::~ABUFSSpecs (void)
  96. {
  97.     //    do nothing!
  98. } // end ~ABUFSSpecs
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /*========================= ABUFSSpecs::GetDirID =================================*/
  105. pascal    OSErr    
  106. ABUFSSpecs::GetDirID(short vRefNum,
  107.                      long dirID,
  108.                      StringPtr name,
  109.                      long *theDirID,
  110.                      Boolean *isDirectory)
  111. {
  112.     CInfoPBRec pb;
  113.     OSErr error;
  114.  
  115.     pb.hFileInfo.ioNamePtr = name;
  116.     pb.hFileInfo.ioVRefNum = vRefNum;
  117.     pb.hFileInfo.ioDirID = dirID;
  118.     pb.hFileInfo.ioFDirIndex = 0;    // use ioNamePtr and ioDirID
  119.     error = ::PBGetCatInfoSync(&pb);
  120.     *theDirID = pb.hFileInfo.ioDirID;
  121.     *isDirectory = (pb.hFileInfo.ioFlAttrib & 0x10) != 0;
  122.     return (error);
  123. }
  124.  
  125.  
  126.  
  127. /*========================= ABUFSSpecs::DirIDFromFSSpec =============================*/
  128.  
  129. pascal    OSErr    
  130. ABUFSSpecs::DirIDFromFSSpec(const FSSpec *spec,
  131.                             long *theDirID,
  132.                             Boolean *isDirectory)
  133. {
  134.     return (ABUFSSpecs::GetDirID(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  135.                                 theDirID, isDirectory));
  136. }
  137.  
  138.  
  139.  
  140.  
  141.  
  142. /*========================= ABUFSSpecs::DetermineVRefNum ============================*/
  143.  
  144. pascal    OSErr
  145. ABUFSSpecs::DetermineVRefNum(StringPtr pathname,
  146.                              short vRefNum,
  147.                              short *realVRefNum)
  148. {
  149.     HParamBlockRec pb;
  150.     Str255 tempPathname;
  151.     OSErr error;
  152.  
  153.     pb.volumeParam.ioVRefNum = vRefNum;
  154.     if (pathname == nil) 
  155.     {
  156.         pb.volumeParam.ioNamePtr = nil;
  157.         pb.volumeParam.ioVolIndex = 0;        // use ioVRefNum only
  158.     } else {
  159.         ::BlockMove ((Ptr)pathname, (Ptr)tempPathname, *pathname + 1);
  160.         pb.volumeParam.ioNamePtr = (StringPtr)tempPathname;    // use the copy so original isn't trashed
  161.         pb.volumeParam.ioVolIndex = -1;    // use ioNamePtr/ioVRefNum combination
  162.     }
  163.     error = ::PBHGetVInfoSync(&pb);
  164.     if (realVRefNum)
  165.         *realVRefNum = pb.volumeParam.ioVRefNum;
  166.     return (error);
  167. }
  168.  
  169.  
  170.  
  171.  
  172.  
  173. /*========================= ABUFSSpecs::GetDirItems ============================*/
  174.  
  175. pascal    OSErr
  176. ABUFSSpecs::GetDirItems(short vRefNum,
  177.                         long dirID,
  178.                         StringPtr name,
  179.                         Boolean getFiles,
  180.                         Boolean getDirectories,
  181.                         FSSpecPtr items,
  182.                         short reqItemCount,
  183.                         short *actItemCount,
  184.                         short *itemIndex) // start with 1, then use what's returned
  185. {
  186.     CInfoPBRec pb;
  187.     OSErr error = noErr;
  188.     long theDirID;
  189.     Boolean isDirectory;
  190.     FSSpec *endItemsArray = items + reqItemCount;
  191.  
  192.     // NOTE: If I could be sure that the caller passed a real vRefNum and real directory 
  193.     // to this routine, I could rip out calls to DetermineVRefNum and GetDirID and this 
  194.     // routine would be much faster because of the overhead of DetermineVRefNum and 
  195.     // GetDirID and because GetDirID blows away the directory index hint the Macintosh 
  196.     // file system keeps for indexed calls. I can't be sure, so for maximum throughput, 
  197.     // pass a big array of FSSpecs so you can get the directory's contents with few calls 
  198.     // to this routine. 
  199.     
  200.     // get the real volume reference number 
  201.     error = ABUFSSpecs::DetermineVRefNum(name, vRefNum, &pb.hFileInfo.ioVRefNum);
  202.     if (error != noErr)
  203.         return (error);
  204.     
  205.     // and the real directory ID of this directory (and make sure it IS a directory 
  206.     error = ABUFSSpecs::GetDirID(vRefNum, dirID, name, &theDirID, &isDirectory);
  207.     if (error != noErr)
  208.         return (error);
  209.     else if (!isDirectory)
  210.         return (dirNFErr);
  211.  
  212.  
  213.     *actItemCount = 0;
  214.     for (; (items < endItemsArray) && (error == noErr); )
  215.     {
  216.         pb.hFileInfo.ioNamePtr = (StringPtr) &items->name;
  217.         pb.hFileInfo.ioDirID = theDirID;
  218.         pb.hFileInfo.ioFDirIndex = *itemIndex;
  219.         error = ::PBGetCatInfoSync(&pb);
  220.         if (error == noErr)
  221.         {
  222.             items->parID = pb.hFileInfo.ioFlParID;    // return item's parID 
  223.             items->vRefNum = pb.hFileInfo.ioVRefNum;    // return item's vRefNum 
  224.             ++*itemIndex;    // prepare to get next item in directory 
  225.             
  226.             if (pb.hFileInfo.ioFlAttrib & 0x10) {
  227.                 if (getDirectories) {
  228.                     ++*actItemCount; // keep this item 
  229.                     ++items; // point to next item 
  230.                 }
  231.             }
  232.             else {
  233.                 if (getFiles) {
  234.                     ++*actItemCount; // keep this item 
  235.                     ++items; // point to next item 
  236.                 }
  237.             }
  238.         }
  239.     }
  240.     return (error);
  241. }
  242.  
  243.  
  244. //    end of file.